schema
Schema
Schema is used to describe a field present in data. Schema definition is a simple key value pair.
Following properties are available on the schema object both for measure and dimension.
Property | Description | Required | Example |
---|---|---|---|
name | Name of the field | true | "sales" |
type | Type of field (dimension or measure) | false (defaults to "dimenson" | "dimension" |
subtype | Subtype of field | false | "Temporal" |
defAggFn | Default aggregation function for measures | false | "sum" |
format | Format specification for dates/numbers | false | "MM/DD/YYYY" |
displayName | Custom name for field display | false | "Total Sales" |
1. name: Name of the variable.
- The field must exist in the data. It is the only mandatory property in schema.
2. type: type of the variable.
- The options are 'measure' and 'dimension'. Default is 'dimension'.
For a dimension
the following fields are available on schema object
subtype
: specifies what kind of dimension it is.- Currently the options are 'categorical', 'temporal' and 'binned'.
- Default is 'categorical'
format
: This filed has a multi usage as described below- If subtype
temporal
and the value type of data of this field is in timestamp then it can have function which will be used to get the value from datamodel in that format. - If subtype
temporal
and the value type of data of this field is in string format , then this should have the format of Date data which will be used to parse the date. - If subtype is
categorical
, this should have a function to format the data in this field.
- If subtype
binSize
: This should be of type Number to provide bin size for binned field.
For a measure
the following fields are available on schema object
subtype
: The subtype for measure is always is 'continuous'defAggFn
: function to be used when field is aggregated.format
: a function which returns the formatted value of a variable. This is only for output purpose.
Name | Miles_per_Gallon | Cylinders | Displacement | Horsepower | Weight_in_lbs | Acceleration | Year | Origin |
---|---|---|---|---|---|---|---|---|
chevrolet chevelle malibu | 18 | 8 | 307 | 130 | 3504 | 12 | 1970 | USA |
ford fiesta | 36.1 | 4 | 98 | 66 | 1800 | 14.4 | 1978 | USA |
bmw 320i | 21.5 | 4 | 121 | 110 | 2600 | 12.8 | 1977 | Europe |
The schema would be something like
[
{
"name": "Name",
"type": "dimension"
},
{
"name": "Maker",
"type": "dimension"
},
{
"name": "Miles_per_Gallon",
"type": "measure",
"defAggFn": DataModel.AggregationFunctions.MAX
},
{
"name": "Displacement",
"type": "measure",
"defAggFn": DataModel.AggregationFunctions.MAX
},
{
"name": "Horsepower",
"type": "measure",
"defAggFn": DataModel.AggregationFunctions.AVG
},
{
"name": "Weight_in_lbs",
"type": "measure",
"defAggFn": DataModel.AggregationFunctions.MIN,
"format": val => `Total weight in pounds ${val}`
},
{
"name": "Acceleration",
"type": "measure",
"defAggFn": DataModel.AggregationFunctions.AVG,
"displayName": "Acc"
},
{
"name": "Origin",
"type": "dimension"
},
{
"name": "Cylinders",
"type": "dimension"
},
{
"name": "Year",
"type": "dimension",
"subtype": "temporal",
"format": "%Y-%m-%d"
}
]